<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The WeakMap class</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="weakref.valid.html">Weakref::valid</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="weakmap.construct.html">WeakMap::__construct</a></div>
 <div class="up"><a href="book.weakref.html">Weakref</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="class.weakmap" class="reference">

 <h1 class="title">The WeakMap class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL weakref &gt;= 0.2.0)</p>


  <div class="section" id="weakmap.intro">
   <h2 class="title">简介</h2>
   <p class="para">

   </p>
  </div>


  <div class="section" id="weakmap.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">WeakMap</strong>
     </span>
     
     <span class="oointerface">implements 
      <span class="interfacename"><a href="class.countable.html" class="interfacename">Countable</a></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><strong class="interfacename">ArrayAccess</strong></span>
     </span>

     <span class="oointerface">, 
      <span class="interfacename"><strong class="interfacename">Iterator</strong></span>
     </span>

     {</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="weakmap.construct.html" class="methodname">__construct</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span><span class="methodname"><a href="weakmap.count.html" class="methodname">count</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">mixed</span><span class="methodname"><a href="weakmap.current.html" class="methodname">current</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">object</span><span class="methodname"><a href="weakmap.key.html" class="methodname">key</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="weakmap.next.html" class="methodname">next</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span><span class="methodname"><a href="weakmap.offsetexists.html" class="methodname">offsetExists</a></span>
    ( <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">mixed</span><span class="methodname"><a href="weakmap.offsetget.html" class="methodname">offsetGet</a></span>
    ( <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="weakmap.offsetset.html" class="methodname">offsetSet</a></span>
    ( <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="weakmap.offsetunset.html" class="methodname">offsetUnset</a></span>
    ( <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">void</span><span class="methodname"><a href="weakmap.rewind.html" class="methodname">rewind</a></span>
    ( <span class="methodparam">void</span>
   )</div>
<div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span><span class="methodname"><a href="weakmap.valid.html" class="methodname">valid</a></span>
    ( <span class="methodparam">void</span>
   )</div>

   }</div>


  </div>

  <div class="section" id="weakmap.examples">
   <h2 class="title">范例</h2>
   <p class="para">
    <div class="example" id="example-527">
     <p><strong>Example #1 <strong class="classname">Weakmap</strong> usage example</strong></p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$wm&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">WeakMap</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$o&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">StdClass</span><span style="color: #007700">;<br /><br />class&nbsp;</span><span style="color: #0000BB">A&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">__destruct</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Dead!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$wm</span><span style="color: #007700">[</span><span style="color: #0000BB">$o</span><span style="color: #007700">]&nbsp;=&nbsp;new&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$wm</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">"Unsetting..\n"</span><span style="color: #007700">;<br />unset(</span><span style="color: #0000BB">$o</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Done\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$wm</span><span style="color: #007700">));</span>
</span>
</code></div>
     </div>

     <div class="example-contents"><p>以上例程会输出：</p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
int(1)
Unsetting..
Dead!
Done
int(0)
</pre></div>
     </div>
    </div>
   </p>
  </div>


 </div>

 
 






 






 






 






 






 






 






 






 






 






 







<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="weakmap.construct.html">WeakMap::__construct</a> — Constructs a new map</li><li><a href="weakmap.count.html">WeakMap::count</a> — Counts the number of live entries in the map</li><li><a href="weakmap.current.html">WeakMap::current</a> — Returns the current value under iteration</li><li><a href="weakmap.key.html">WeakMap::key</a> — Returns the current key under iteration.</li><li><a href="weakmap.next.html">WeakMap::next</a> — Advances to the next map element</li><li><a href="weakmap.offsetexists.html">WeakMap::offsetExists</a> — Checks whether a certain object is in the map</li><li><a href="weakmap.offsetget.html">WeakMap::offsetGet</a> — Returns the value pointed to by a certain object</li><li><a href="weakmap.offsetset.html">WeakMap::offsetSet</a> — Updates the map with a new key-value pair</li><li><a href="weakmap.offsetunset.html">WeakMap::offsetUnset</a> — Removes an entry from the map</li><li><a href="weakmap.rewind.html">WeakMap::rewind</a> — Rewinds the iterator to the beginning of the map</li><li><a href="weakmap.valid.html">WeakMap::valid</a> — Returns whether the iterator is still on a valid map element</li></ul>
</div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="weakref.valid.html">Weakref::valid</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="weakmap.construct.html">WeakMap::__construct</a></div>
 <div class="up"><a href="book.weakref.html">Weakref</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
